﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using Microsoft.Xna.Framework.Media;
using MS.TravelJourney.Final.Core;
using Windows.Phone.Speech.Recognition;
using Windows.Phone.Speech.Synthesis;
using MS.TravelJourney.Final.ViewModels;

namespace MS.TravelJourney.Final
{
    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();
        }

        // 为 ViewModel 项加载数据
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                await App.ViewModel.LoadData();
                // 将 listbox 控件的数据上下文设置为示例数据
                DataContext = App.ViewModel;
                progressBar.IsVisible = false;
            }
            var color = new MS.TravelJourney.Final.Core.Util().LoadDataSettings();
            if (!string.IsNullOrEmpty(color))
                new MS.TravelJourney.Final.Core.Util().ModifyBackgroundStyle(color);
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
        }

        private void ApplicationBarIconButton_Click_2(object sender, EventArgs e)
        {
            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Caption = "Travel Journey",
                Message = "Travel joryney is a windows phone application, aim is show how to create a windows phone application.",
                LeftButtonContent = "确定"
            };
            messageBox.Show();
        }
        private void LongListSelector_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var item = (sender as LongListSelector).SelectedItem as ItemViewModel;
            NavigationService.Navigate(new Uri("/ItemDetail.xaml?name="+item.Name, UriKind.Relative));
        }
    }
}